﻿@model Tasks.UI.Models.Power.MenuRolePowerModel
<!DOCTYPE html>
<html>
<head>
    <title>分配菜单权限</title>
    <link href="@Config.GetCssResourcePath("main.css")" rel="stylesheet" type="text/css" />
    <link href="@Config.GetCssResourcePath("table.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Scripts/jquery-impromptu.3.1.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-impromptu.3.1.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/global.js")" type="text/javascript"></script>
    <script type="text/javascript">

            $(function () {
                @Html.AlertMessage("提示", Model.Message, Model.MessageType, 2500)
            })
            //全选 
        function checkall() {
            var obj = $(".CheckAll");
            obj.attr("checked", true);
        }


//反选
        function uncheckall() {
            $(".CheckAll").each(function () {
                if ($(this).attr("checked")) {
                    $(this).attr("checked", false);
                }
                else {
                    $(this).attr("checked", true);
                }
            });
        }
     
    </script>
</head>
<body>
    @using (Html.BeginForm())
    {
        @Html.HiddenFor(t => t.RoleId)
        <div class="navTitle">
            分配菜单</div>
        <div>
            <table class="tblStyle1" border="1" style="table-layout: fixed; width: 100%;">
                <thead>
                    <tr>
                        <th style="width: 200px">
                            父菜单 @Html.HiddenFor(t => t.RoleId)
                        </th>
                        <th align="left">
                            子菜单
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (Menu m in Model.MenuParent.Where(t => t.ParentID == 0))
                    {<tr>
                        <td style="text-align: center">
                            @if (Model.ParentMenuidStr.IndexOf(("," + m.ID) + ",") != -1)
                            {
                                <input type="checkbox" checked="checked"  name="MenuParentID"  value="@m.ID" class="CheckAll"/>
                            }
                            else
                            {
                                <input type="checkbox"   name="MenuParentID"  value="@m.ID" class="CheckAll"/>
                            }
                            @m.Name
                        </td>
                        <td style="text-align: left;">
                            @{
                       IList<Menu> menus = Model.MenuChild.Where(t => t.ParentID == m.ID).ToList();
                            }
                            @foreach (Menu childMenu in menus)
                            {
                                if (Model.MenuidStr.IndexOf(("," + childMenu.ID) + ",") != -1)
                                {
                                <input type="checkbox" checked="checked"  name="MenuID" value="@childMenu.ID" class="CheckAll" />
                                }
                                else
                                {
                                <input type="checkbox"  name="MenuID"  value="@childMenu.ID" class="CheckAll"/>
                                }
                                <label>
                                    @childMenu.Name</label>
                            }
                        </td>
                    </tr>
                    }
                </tbody>
            </table>
        </div>
        
        <a href="javascript:void(0)" onclick="checkall()">全选</a>
        <a href="javascript:void(0)" onclick="uncheckall()">反选</a>
        <div class="BottomBtn">
            <button class="big blue" type="submit">
                <span>保存权限</span></button></div>
    }
</body>
</html>
